﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NBusiness.Data.Providers.SqlServer.Query;

namespace NBusiness.Query.Testing
{
    [TestClass]
    class DeleteTests
    {
        [TestMethod]
        public void TestDeleteSuccess1()
        {
            ITable t = new SqlTable("T");
            IColumn c = new SqlColumn("c");
            IParameter p = new SqlParameter("p");

            IQuery query = new SqlQuery();
            query.Delete().From(t).Where(c.Equal(p));

            string expected = "DELETE FROM [T] WHERE ([c]=@p)";
            string actual = query.ToSql();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestDeleteSuccess2()
        {
            ITable t = new SqlTable("T");
            IColumn c = new SqlColumn("c");

            IQuery query = new SqlQuery();
            query.Delete().From(t);

            string expected = "DELETE FROM [T]";
            string actual = query.ToSql();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestDeleteFail1_MissingTable()
        {
            IQuery query = new SqlQuery();
            query.Delete();
            query.ToSql();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestDeleteFail2_MissingTable()
        {
            IColumn c = new SqlColumn("c");
            IParameter p = new SqlParameter("p");

            IQuery query = new SqlQuery();
            query.Delete().Where(c.Equal(p));
            query.ToSql();
        }
    }
}
